<%@page import="org.json.JSONObject"%>
<%@page import="org.jfaster.db.Configs"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="com.itsm.v17.entity.WorkOrderOpinion"%>
<%@page import="java.util.List"%>
<%@page import="com.kflow.workflow.po.RecFlow"%>
<%@ page pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
RecFlow flow=(RecFlow)request.getAttribute("flow");
List list=(List)request.getAttribute("opinion");
String orderId="";
String id="";
String context="";
int grade=4;
int serviceGrade=4;
String display="";
String readonly="";
String flowTitile="";

Date completeDate= null;
String completeDateString="";
String endDateString="";
if(flow!=null)
{
	flowTitile=flow.getTitle();
	orderId=flow.getSerialNO();
	completeDate= flow.getCompletedate();
}else
{
	display="none";
	readonly="readonly='readonly'";
}
//System.out.println("opinion.size="+list.size());
if((list!=null)&&(list.size()>0))
{
	WorkOrderOpinion opinion=(WorkOrderOpinion)list.get(0);
	//System.out.println("opinion="+JSONObject.wrap(opinion));
	//System.out.println("opinion="+opinion.getGrade()+","+opinion.getServiceGrade());
	grade=opinion.getGrade();
	serviceGrade=opinion.getServiceGrade();
	//System.out.println("opinion="+grade+","+serviceGrade);
	context=opinion.getContent();
	id=opinion.getId();
	display="none";
	readonly="readonly='readonly'";
}


%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>工单评价</title>
<script src="<%=basePath%>itsm/js/ajax.js"></script>
<script src="<%=basePath%>itsm/js/formValidate.js"></script>
<style>
body
{
font-size:40px;
}
.show{
display:<%=display%>;
}
.small{
font-size: 40px;
line-height: 200%;
}
.button{
background: red none repeat scroll 0 0;
    color: white;
    display: block;
    padding: 10px;
    text-decoration: none;
}
span.active {
    background: #4f77aa none repeat scroll 0 0;
    color: white;
}
</style>
</head>
<body>

	<table width="100%" id="dataTable" >
		<tr><td><b><%=flowTitile%></b></td></tr>
		<tr class="small" style="display:none;" ><td>
			工单完成时间:<%=completeDateString %>
			<br/>
			评价截止时间:<%=endDateString %>
		</td></tr>
		<tr class="small"><td>工程师评价</td></tr>
		<tr><td>
			<input type="hidden" id="grade" value="<%=grade%>" />
			<iframe src="<%=basePath%>itsm/plugins/opinion/index.jsp?type=grade&grade=<%=grade%>"  width="100%" 
			height="50px" frameborder="0" scrolling="no" ></iframe>
		</td></tr>
		<tr class="small"><td>服务台评价</td></tr>
		<tr><td>
			<input type="hidden" id="serviceGrade" value="<%=serviceGrade%>" />
			<iframe src="<%=basePath%>itsm/plugins/opinion/index.jsp?type=serviceGrade&grade=<%=serviceGrade%>"  width="100%" 
			height="50px" frameborder="0" scrolling="no" ></iframe>
		</td></tr>
		<tr>
			<td>
				<div style="font-size: 12px;padding: 20px 10px;border-top: 1px solid #ddd;" class="add-commoent-prize" ng-hide="formData.isReadonly" id="items">
			<span style="margin-right: 8px;display: inline-block;line-height: 20px;padding: 5px 13px;border: 1px solid #ccc;border-radius: 4px;" onclick="fixText('非常满意',0)" >非常满意</span>
			<span style="margin-right: 8px;display: inline-block;line-height: 20px;padding: 5px 13px;border: 1px solid #ccc;border-radius: 4px;" onclick="fixText('响应及时',1)">响应及时</span>
			<span style="display: inline-block;line-height: 20px;padding: 5px 13px;border: 1px solid #ccc;border-radius: 4px;" onclick="fixText('态度好，服务棒！',2)">态度好，服务棒！</span>
		</div>
			</td>
		</tr>
		<tr class="small"><td>评价内容</td></tr>
		<tr><td>
		<textarea class="small" width="100%" <%=readonly%> rows="3" id="content" 
		require=true max=200 min=1	message="评价内容需要输入且最多200个字符" style="width:100%;"><%=context%></textarea>
		</td></tr>
		
		<tr class="show">
		<td align="center">
			<a class="button" href="javascript:;" onclick="submitOpinion()" id="button_submit" >提 交 </a>
		</td>
		</tr>
		<tr class="show">
		<td align="center">
			<a class="button" href="<%=path%>/itsm17/prize/home/index.html" id="button_prize" style="display:none;" >点击抽奖 </a>
		</td>
		</tr>
		<tr class="small"><td align="center"><span id="message"></span></td></tr>
	</table>
<script>
var orderId="<%=orderId%>";
var hasActivityObject;
function starCall(type,grade)
{
	//orderId=type;
	//grade=gradeTemp;
	get(type).value=grade;
}
function submitOpinion()
{
	get("message").innerHTML='';
	//var flag=formValidate("dataTable");
	//if(!flag){return;}
	var content=get("content").value+"";
	if(content.trim().length == 0){get("message").innerHTML="评价内容需要输入且最多200个字符";return;}
	
	get("message").innerHTML="正在提交...";
	//return;
	var args="id=<%=id%>";
	args=args+"&workOrderId="+orderId;
	args=args+"&grade="+get("grade").value;
	args=args+"&serviceGrade="+get("serviceGrade").value;
	args=args+"&content="+encodeURI(encodeURI(get("content").value));
	new ajax({"url":"<%=path%>/itsm17/workorder/opinion/save","params":args,"success":function(data)
		{
			get("message").innerHTML='';
			var json=toJson(data);
			if(json.result)
			{
				hidden("button_submit");
				//show("button_prize");
				/*
				if((hasActivityObject != undefined)&&(hasActivityObject.result == true))
				{
					get("message").innerHTML='<font color=green>提交成功,正在跳转到抽奖页面...</font>';	
					setTimeout(function(){window.location.href="<%=path%>/itsm-prize/index.html";},800);
				}else
				{
					get("message").innerHTML='<font color=green>提交成功</font>';	
				}
				*/
				get("message").innerHTML='<font color=green>提交成功,正在跳转到抽奖页面...</font>';	
				window.location.href="<%=path%>/itsm-prize/index.html";
			}else
			{
				get("message").innerHTML='<font color=red>'+json.message+'</font>';	
			}
		}});
}

function fixText(text,index)
{
	var items=document.getElementById("items").getElementsByTagName("span");
	for(var i=0;i<items.length;i++)
	{
		items[i].className="";
	}
	items[index].className="active";
	get("content").value=text;
}
</script>
</body>
</html>
